package com.ruoyi.nas.files.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.nas.files.domain.NasFiles;
import com.ruoyi.nas.files.service.INasFilesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * NAS文件Controller
 * 
 * @author ruoyi
 * @date 2025-09-08
 */
@Api("Nas文件管理")
@RestController
@RequestMapping("/nas/files")
public class NasFilesController extends BaseController
{
    @Autowired
    private INasFilesService nasFilesService;

    /**
     * 查询NAS文件列表
     */
    @ApiOperation("获取文件列表")
    @PreAuthorize("@ss.hasPermi('nas:files:list')")
    @GetMapping("/list")
    public TableDataInfo list(NasFiles nasFiles)
    {
        startPage();
        List<NasFiles> list = nasFilesService.selectNasFilesList(nasFiles);
        return getDataTable(list);
    }

    /**
     * 导出NAS文件列表
     */
    @PreAuthorize("@ss.hasPermi('nas:files:export')")
    @Log(title = "NAS文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NasFiles nasFiles)
    {
        List<NasFiles> list = nasFilesService.selectNasFilesList(nasFiles);
        ExcelUtil<NasFiles> util = new ExcelUtil<NasFiles>(NasFiles.class);
        util.exportExcel(response, list, "NAS文件数据");
    }

    /**
     * 获取NAS文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('nas:files:query')")
    @GetMapping(value = "/{filename}")
    public AjaxResult getInfo(@PathVariable("filename") String filename)
    {
        return AjaxResult.success(nasFilesService.selectNasFilesByFilename(filename));
    }

    /**
     * 新增NAS文件
     */
    @PreAuthorize("@ss.hasPermi('nas:files:add')")
    @Log(title = "NAS文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NasFiles nasFiles)
    {
        return toAjax(nasFilesService.insertNasFiles(nasFiles));
    }

    /**
     * 修改NAS文件
     */
    @PreAuthorize("@ss.hasPermi('nas:files:edit')")
    @Log(title = "NAS文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NasFiles nasFiles)
    {
        return toAjax(nasFilesService.updateNasFiles(nasFiles));
    }

    /**
     * 删除NAS文件
     */
    @PreAuthorize("@ss.hasPermi('nas:files:remove')")
    @Log(title = "NAS文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{filenames}")
    public AjaxResult remove(@PathVariable String[] filenames)
    {
        return toAjax(nasFilesService.deleteNasFilesByFilenames(filenames));
    }
}
